import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'

//引用全局样式和字体库
import './assets/css/gobal.css'
import './assets/fonts/iconfont'

//启用element-ui
import ElementUI from 'element-ui'
Vue.use(ElementUI)
import 'element-ui/lib/theme-chalk/index.css';

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  //获取令牌
  const token = sessionStorage.getItem('token')
  if (!token) return next('/login')
})

axios.defaults.baseURL = 'https://www.liulongbin.top:8888/api/private/v1/'
Vue.prototype.$http = axios
//在请求头中加入令牌
axios.interceptors.request.use(
  function(config) {
    //获取到令牌
    const token = sessionStorage.getItem('token')

    cofig.headers.Authorization = token
    return config
  },
  function(error) {
    return Promise.reject(error)
  }
)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
 